#include "reports.h"

#include "display.h"
#include "usb.h"
#include "vx.h"

static uint buf[32]={RPT_ACCREC,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
	RPT_ACCREC,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,};
static ubyte rptOk;

//------------------------------------------------------------------------------

ubyte prepare(int x,int y,int z,ubyte stt){
	static uint *ptr=buf+1;
	*ptr++=((x>>6)&0x000003ff)+((y<<5)&0x1ff800)+((z<<16)&0xffc00000);
	if(ptr==buf+16){
		rptOk=1;
		ptr++;
	}else if(ptr>=buf+32){
		rptOk=2;
		ptr=buf+1;
	}
	return COUNT_SEARCHING;
}
void report(void){
	if(!usbBusy()){
		if(rptOk==1)
			sendReport(buf);
		else if(rptOk==1)
			sendReport(buf+16);
		else{
			int v=RTC_GetCounter();
			reports.tickLoV=v;
			reports.tickHiV=v>>16;
			reports.offsetLoV=savRam.timeOfs;
			reports.offsetHiV=savRam.timeOfs>>16;
			reports.currentLoV=curSteps;
			reports.currentHiV=curSteps>>16;
			sendReport(&reports);
			return;
		}
		rptOk=0;
	}
}